package com.cw.base.jeeyc.biz.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cw.base.jeeyc.biz.converter.ApiDatabaseConverter;
import com.cw.base.jeeyc.biz.intf.ApiDatabaseBiz;
import com.cw.base.jeeyc.dao.mapper.ApiDatabaseMapper;
import com.cw.base.jeeyc.dao.model.ApiDatabaseDo;
import com.cw.base.jeeyc.api.dto.ApiDatabaseDto;
import com.cw.lang.common.framework.aop.annotation.RetryerHandler;

import lombok.extern.slf4j.Slf4j;

/**
 * api数据库信息接口业务实现类
 *
 * @author chenw
 * @date 2019-08-24 10:59:29
 */
@Service
@Slf4j
public class ApiDatabaseBizImpl extends ServiceImpl<ApiDatabaseMapper, ApiDatabaseDo> implements ApiDatabaseBiz {
    /**
     * 新增api数据库信息
     *
     * @param request 条件
     * @return String
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean addApiDatabase(ApiDatabaseDto request) {
        if (request == null) {
            return null;
        }
        return getBaseMapper().insert(ApiDatabaseConverter.dto2Do(request))>0;
    }

    /**
     * 更新api数据库信息
     *
     * @param request 条件
     * @return boolean
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean modifyApiDatabase(ApiDatabaseDto request) {
        if (request == null) {
            return false;
        }
        getBaseMapper().updateById(ApiDatabaseConverter.dto2Do(request));
        return true;
    }

    /**
     * 删除api数据库信息
     *
     * @param request 条件
     * @return boolean
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteApiDatabase(ApiDatabaseDto request) {
        if (request == null) {
            return false;
        }
        return getBaseMapper().deleteById(request.getId()) > 0;
    }

    @Override
    @RetryerHandler(maxAttempt = 3,retryThrowable = Exception.class)
    public String retryTest(){
        log.info("测试重试");
        return "false";
    }
    @Override
    public void hello() {
        log.info("hello world sentinel");
    }
}
